<template>
  <div class="classAll">
    <div :key="item.id" v-for="item in types" class="myGoods">
      <div class="goodsImg">
        <img :src="item.pics[0]" alt="">
      </div>
      <div class="goodsTit">
        <span>{{item.des}}</span>
      </div>
      <div class="tuan clear">
        <div class="goodsPeople"><span>2-4人团</span></div>
        <div class="goodsPrice">{{'￥'+item.price}}</div>
        <van-button type="default" class="tuanBtn" @click="goto(item.id)">去开团</van-button>
      </div>
    </div>
    <!--<div class="conFooter">
      <span>亲，我也是有底线的</span>
    </div>-->
  </div>
</template>

<script>
  export default {
    props: ['commodities', 'type'],
    name: "classGoods",
    data() {
      return {
        types: "",
      }
    },
    created() {
      this.types = this.goodsType(this.type, this.commodities);
    },
    methods: {
      goodsType(type, commodities) {
        let myType = [];
        for (let i = 0; i < commodities.length; i++) {
          if (type===0){
            myType.push(commodities[i]);
          }else if (type === commodities[i].cid) {
            myType.push(commodities[i]);
          }
        }
        return myType;
      },
      goto(i){
        this.$router.push({
          path:'/productDetails',
          params:{
            id:i
          }
        })
      }
    }
  }
</script>

<style scoped>
  *{
    padding: 0;
    margin: 0;
  }
  .clear::before,
  .clear::after{
    display: table;
    content: '';
  }
  .clear::after{
    clear: both;
  }
  .myGoods {
    width: 100%;
    padding: 10px 0;
    text-align: left;
  }
  .goodsImg {
    width: 100%;
    height: 150px;
    border-top: 1px solid #6a6363;
    border-bottom: 1px solid #6a6363;
  }
  .goodsImg > img {
    object-fit: cover;
    width: 100%;
    height: 100%;
  }
  .goodsTit{
    font-size: 16px;
    margin: 10px 2%;
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
  }

  .tuan{
    padding: 5px 2%;
    height: 30px;
    line-height: 30px;
    position: relative;
  }
  .goodsPeople{
    font-size: 15px;
    color: #a8a8a8;
    float: left;
  }
  .goodsPrice{
    font-size: 25px;
    color: #fc0404;
    font-weight: bold;
    float: left;
    padding-left: 5%;
  }
  .tuanBtn{
    width: 20%;
    height: 30px;
    background-color: #FF0000;
    color: #fff;
    float: right;
    border-radius: 5px;
  }

</style>
